<?php
if($this->identity){
?>
<div class="forumButton">
<span><a href="/community/create-topic/fid/<?php echo $this->topic->forum_id;?>"><img src = "/skins/common/new_topic.png" /></a></span>
<span><a href="/community/create-post/tid/<?php echo $this->topic->id;?>"><img src = "/skins/common/reply_topic.png" /></a></span>
<?php
    if($this->identity->id == $this->topic['user_id']){
        echo "<span><a href='/community/update-topic/id/".$this->topic->id."'><img src = '/skins/common/edit_topic.png' /></a></span>";
    }
    if ($this->identity->role == 'admin'){
        echo " <span><a href = '/community/delete-topic/id/".$this->topic->id."'><img src = '/skins/common/delete.png' /></a></span>";
    }
?>
</div>
<?php
}
?>

<table class="forum">
  <thead>
    <tr class="title">
        <td width="10%">
            <?php
            if ($this->user->avatar){
                echo "<img src = '/uploads/".$this->user->avatar."' class='title'>";
            }
            else{
                echo "<img src = '/skins/common/avatar_nobody.gif' class='title'>";
            }
                echo "<a href='/user/account/id/".$this->user->id."'>".$this->user->username."</a><br />";
                switch ($this->user->role){
                case "user":
                    echo "用户";
                    break;
                case "auth":
                    echo "作者";
                    break;
                case "editor":
                    echo "编辑";
                    break;
                case "admin":
                    echo "管理员";
                    break;
            }
                echo "<br />注册:".date("Y-m-d",$this->user->time_reg);
            ?>
        </td>
        <td>
            <?php
                echo "<h3>".$this->topic->subject."</h3>";
                echo "<p>".$this->topic->post."</p>";
             ?>
        </td>
        <?php 

        ?>
    </tr>
  </thead>
      <?php
        foreach ($this->posts as $post){
              echo "<tr>";
              echo "<td rowspan='2'>";
              echo "<a href='/user/account/id/'.$post->user_id>";
            if ($post->avatar){
                echo "<img src = '/uploads/".$post->avatar."' class = 'title'/>";
            }
            else{
                echo "<img src = '/skins/common/avatar_nobody.gif' />";
            }
            echo "</a>";
            echo "<a href='/user/account/id/".$post->user_id."'>".$post->username."</a><br />";
            switch ($post->role){
                case "user":
                    echo "用户";
                    break;
                case "auth":
                    echo "作者";
                    break;
                case "editor":
                    echo "编辑";
                    break;
                case "admin":
                    echo "管理员";
                    break;
            }
            echo "<br />注册:".date("Y-m-d",$post->time_reg);
            echo "</td>";
            echo "<td>".$post->post."</td>";
            echo "</tr>";
            echo "<tr>";
            // 身份
            if($this->identity){
                echo "<td>";
                if($this->identity->role == 'admin'){
                    echo "<a href = '/community/update-post/id/".$post->id."'>编辑</a>";
                    echo " | <a href = '/community/delete-post/id/".$post->id."'>删除</a>";
                }
                else{
                    $time = time() - $post->time; //帖子发表距现在的时间
                    if($this->identity->id == $post->user_id and $time < 86400){
                        echo "<a href='/community/update-post/id/".$post->id."'>编辑";
                    }
                }
                echo "</td>";
            }
            echo "</tr>";
        }
    ?>
</table>

<?php
if(count($this->posts) > 1 ){
    echo $this->paginationControl($this->posts,'Sliding','partials/pagination-control.phtml');
}
?>

<script type="text/javascript" src="/js/ckeditor/ckeditor.js"></script>

<?php echo $this->comment; ?>

<script type="text/javascript">
      CKEDITOR.replace( 'comment',
         {
              toolbar : 'Basic',
                height:100
      });
</script>
